home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / gus / vts139b.zip / MOUSE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-05  |  25KB  |  1,234 lines

  1. unit Mouse;
  2. {$S-,R-}
  3.  
  4. interface
  5.  
  6.  
  7.  
  8.                                          { ╨    ╬    ╥    ╙    ╘    ╒    ╓    ╫    ╪  }
  9. const  MouseUDGs  : array[0..8] of byte= ($d0, $ce, $d2, $d3, $d4, $d5, $d6, $d7, $d8);
  10. var    MouseAttrs : array[0..8] of byte;
  11.  
  12.  
  13. const  mouPointer   = 0;
  14.        mouWaitClock = 1;
  15.  
  16.  
  17. { Si la llamada se realiza después de InitEvents, no estará disponible Mouse }
  18. procedure InitMouse;
  19. procedure DoneMouse;
  20. procedure MOUReset(full: boolean);
  21.  
  22. procedure SetMouse(On: boolean);  { Muestra el cursor texto/cursor grafico }
  23. function  MouseAvail: Boolean;    { El ratón gráfico puede ser utilizado   }
  24.  
  25.  
  26. procedure RepaintMouse;            { Repinta el raton, puede ser llamado desde el idle }
  27.                                    {  sirve par corregir la pega de que TV nos borrar  }
  28.  
  29.  
  30. procedure SelectMouseCursor(mouCur: word);
  31.  
  32.  
  33. PROCEDURE ShowMouse; 
  34. PROCEDURE HideMouse; 
  35.  
  36.  
  37.  
  38. implementation
  39.  
  40. var
  41.   DEFCHAR : array[0..8] of byte absolute MouseUDGs;
  42.  
  43.   mousex,              { Coordenadas del cursor         }
  44.   mousey   : word;     {   .. en baja resolucion        }
  45.   mousepx,             {   .. en alta resolucion        }
  46.   mousepy  : word;
  47.  
  48.  
  49.  
  50.                         { Datos sobre video   }
  51.   vseg      : word;     { Segmento de video   }
  52.   vofs      : word;     { Offset   de video   }
  53.   mcols,
  54.   mrows     : word;
  55.   points    : word;
  56.   b_points  : byte absolute $40:$85;
  57.  
  58.   maxx,
  59.   maxy      : word;
  60.  
  61.  
  62.  
  63.                         { Sprites para el cursor        }
  64.   savechars : array[0..2, 0..2] of word;
  65.   chardefs  : array[0..32*9-1] of byte;
  66.   chardefsL  : array[0..8*9 -1] of longint absolute chardefs;
  67.  
  68.  
  69.  
  70. const
  71.   cur_height  = 16;
  72.  
  73.   SecondaryFontOfs = 32*256*2;
  74.  
  75.  
  76. var  
  77.   mousecursormask : array[0..cur_height-1] of longint;
  78.   mousescreenmask : array[0..cur_height-1] of longint;
  79.  
  80. const
  81.   cur_Pointer_fore  : array[0..cur_height-1] of longint= (
  82.     $00000000,  { 0000000000000000 }
  83.     $40000000,  { 0100000000000000 }
  84.     $60000000,  { 0110000000000000 }
  85.     $70000000,  { 0111000000000000 }
  86.     $78000000,  { 0111100000000000 }
  87.     $7c000000,  { 0111110000000000 }
  88.     $7e000000,  { 0111111000000000 }
  89.     $7f000000,  { 0111111100000000 }
  90.     $7f800000,  { 0111111110000000 }
  91.     $7f000000,  { 0111111100000000 }
  92.     $7c000000,  { 0111110000000000 }
  93.     $66000000,  { 0110011000000000 }
  94.     $06000000,  { 0000011000000000 }
  95.     $03000000,  { 0000001100000000 }
  96.     $03000000,  { 0000001100000000 }
  97.     $00000000   { 0000000000000000 }
  98.   );
  99.  
  100.   cur_Pointer_back  : array[0..cur_height-1] of longint= (
  101.     $3fffffff,  { 0011111111111111 }
  102.     $1fffffff,  { 0001111111111111 }
  103.     $0fffffff,  { 0000111111111111 }
  104.     $07ffffff,  { 0000011111111111 }
  105.     $03ffffff,  { 0000001111111111 }
  106.     $01ffffff,  { 0000000111111111 }
  107.     $00ffffff,  { 0000000011111111 }
  108.     $007fffff,  { 0000000001111111 }
  109.     $003fffff,  { 0000000000111111 }
  110.     $007fffff,  { 0000000001111111 }
  111.     $01ffffff,  { 0000000111111111 }
  112.     $00ffffff,  { 0000000011111111 }
  113.     $90ffffff,  { 1001000011111111 }
  114.     $f87fffff,  { 1111100001111111 }
  115.     $f87fffff,  { 1111100001111111 }
  116.     $fcffffff   { 1111110011111111 }
  117.   );
  118.  
  119. (*
  120.   cur_WaitClock_fore : array[0..cur_height-1] of longint= (
  121.     $00000000,  { 0..............0 }
  122.     $3ffc0000,  { 0.111111111111.0 }
  123.     $3ffc0000,  { 0.111111111111.0 }
  124.     $14280000,  { 0..1.1....1.1..0 }
  125.     $16680000,  { 00.1.11..11.1.00 }
  126.     $17e80000,  { 00.1.111111.1.00 }
  127.     $13c80000,  { 00.1..1111..1.00 }
  128.     $11880000,  { 00.1...11...1.00 }
  129.     $11880000,  { 00.1...11...1.00 }
  130.     $12480000,  { 00.1..1..1..1.00 }
  131.     $12480000,  { 00.1..1..1..1.00 }
  132.     $14280000,  { 00.1.1....1.1.00 }
  133.     $15a80000,  { 0..1.1.11.1.1..0 }
  134.     $3ffc0000,  { 0.111111111111.0 }
  135.     $3ffc0000,  { 0.111111111111.0 }
  136.     $00000000   { 0.............00 }
  137.   );
  138.  
  139.   cur_WaitClock_back : array[0..cur_height-1] of longint= (
  140.     $8001ffff,  { 1..............1 }
  141.     $8001ffff,  { 1.000000000000.1 }
  142.     $8001ffff,  { 1.000000000000.1 }
  143.     $8001ffff,  { 1..0.0....0.0..1 }
  144.     $c003ffff,  { 11.0.00..00.0.11 }
  145.     $c003ffff,  { 11.0.000000.0.11 }
  146.     $c003ffff,  { 11.0..0000..0.11 }
  147.     $c003ffff,  { 11.0...00...0.11 }
  148.     $c003ffff,  { 11.0...00...0.11 }
  149.     $c003ffff,  { 11.0..0..0..0.11 }
  150.     $c003ffff,  { 11.0..0..0..0.11 }
  151.     $c003ffff,  { 11.0.0....0.0.11 }
  152.     $8001ffff,  { 1..0.0.00.0.0..1 }
  153.     $8001ffff,  { 1.000000000000.1 }
  154.     $8001ffff,  { 1.000000000000.1 }
  155.     $8001ffff   { 1..............1 }
  156.   );
  157. *)
  158.  
  159.  
  160. const
  161.   prettymouseavail    : boolean= false;  { El gestor de raton esta inicializado }
  162.   prettymousevisible  : boolean= false;  { El cursor grafico esta siendo usado  }
  163.  
  164.  
  165.   mousefreeze  : word   = 0;     { Semaforo                  }
  166.   saved        : boolean= false; { Hay fondo preservado?     }
  167.   mousehidden  : word   = 0;     { Cuenta de hidden          }
  168.   inhandler    : boolean= false;
  169.  
  170.  
  171.                 { Eventos de raton        }
  172.   MOUSEMOVE      = 1;
  173.   LEFTBPRESS     = 2;
  174.   LEFTBRELEASE   = 4;
  175.   RIGHTBPRESS    = 8;
  176.   RIGHTBRELEASE  = 16;
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. {**********************************************************************
  191.   INTERNA: pinta y salva la rejilla
  192.  
  193.  
  194.              func== 0  -->  Restaura la pantalla
  195.              func== 1  -->  Anota el contenido de la pantalla
  196.              func== 2  -->  Pinta el cursor
  197. **********************************************************************}
  198. procedure plotegavgacursor(func: word);
  199. var
  200.   off      : word;
  201.   width,
  202.   height,
  203.   i,
  204.   j        : word;
  205.   disp     : word;
  206.   x,
  207.   y        : word;
  208.   p1       : pointer;
  209. const
  210.   lsavex   : integer= 0;
  211.   lsavey   : integer= 0;
  212.   savedcur : boolean= false;
  213.  
  214. begin
  215.   case func of
  216.     0: begin
  217.          savedcur:= false;
  218.          x:= lsavex;
  219.          y:= lsavey;
  220.        end;
  221.  
  222.     1: begin
  223.          x:= mousex;
  224.          y:= mousey;
  225.        end;
  226.  
  227.     2: begin
  228.          savedcur:= true;
  229.          lsavex:= mousex; x:= mousex;
  230.          lsavey:= mousey; y:= mousey;
  231.        end;
  232.   end;
  233.  
  234.   width:= mcols - x;
  235.   if (width> 3) then width:= 3;
  236.   height:= mrows - y;
  237.   if (height> 3) then height:= 3;
  238.  
  239.   off:= y * (mcols * 2) + x * 2 + vofs;
  240.   disp:= (mcols * 2) - width * 2;
  241.  
  242.   p1:= ptr(vseg, off);
  243.  
  244.   case func of
  245.     0: asm
  246.          push  ds
  247.          push  es
  248.  
  249.          mov   bx, offset DEFCHAR
  250.          les   di, p1
  251.          mov   si, offset savechars
  252.          mov   cx, height
  253.          cld
  254.  
  255. @@l1:
  256.          push  si
  257.          push  bx
  258.          push  cx
  259.          mov   cx, width
  260. @@l2:
  261.          mov   al, ds:[bx]
  262.          mov   ah, ds:[si+1]
  263.          and   ah, 0F7h
  264.          cmp   al, es:[di]
  265.          jne   @@nx
  266.          mov   dl, ds:[si]
  267.          mov   es:[di], dl
  268. @@nx:
  269.          cmp   ah, es:[di+1]
  270.          jne   @@nx1
  271.          mov   dl, ds:[si+1]
  272.          mov   es:[di+1], dl
  273. @@nx1:
  274.          inc   bx
  275.          add   si, 2
  276.          add   di, 2
  277.          loop  @@l2
  278.          pop   cx
  279.  
  280.          pop   bx
  281.          pop   si
  282.          add   si, 6
  283.          add   bx, 3
  284.          add   di, disp
  285.          loop  @@l1
  286.  
  287.  
  288.          pop   es
  289.          pop   ds
  290.        end;
  291.  
  292.     1: asm
  293.          push  ds
  294.          push  es
  295.  
  296.          mov   bx, offset savechars
  297.          mov   si, offset DEFCHAR
  298.          les   di, p1
  299.          mov   cx, height
  300.          cld
  301. @@l1:
  302.          push  si
  303.          push  cx
  304.          push  bx
  305.          mov   cx, width
  306. @@l2:
  307.          lodsb
  308.          inc   bx
  309.          mov   ah,[bx]
  310.          and   ah,0F7h
  311.          stosw
  312.          inc   bx
  313.          loop  @@l2
  314.          pop   bx
  315.          add   bx, 6
  316.          pop   cx
  317.  
  318.          pop   si
  319.          add   si, 3
  320.          add   di, disp
  321.          loop  @@l1
  322.  
  323.          pop   es
  324.          pop   ds
  325.        end;
  326.  
  327.     2: asm
  328.          push  ds
  329.          push  es
  330.  
  331.          push  ds
  332.          pop   es
  333.          lds   si, p1
  334.          mov   di, offset savechars
  335.          mov   cx, height
  336.          cld
  337. @@l1:
  338.          push  di
  339.          push  cx
  340.          mov   cx, width
  341. @@l2:
  342.          lodsw
  343.          stosw
  344.          loop  @@l2
  345.          pop   cx
  346.  
  347.          pop   di
  348.          add   di, 6
  349.          add   si, disp
  350.          loop  @@l1
  351.  
  352.          pop   es
  353.          pop   ds
  354.        end;
  355.   end;
  356. end;
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365. {**********************************************************************
  366.   INTERNA: calcula la rejilla, esta es la que de verdad pinta.
  367. **********************************************************************}
  368. procedure drawegavgacursor;
  369. var
  370.   off     : word;
  371.   i,
  372.   j       : word;
  373.   s1,
  374.   s2,
  375.   s3      : word;
  376.   defs    : ^longint;
  377.   masks   : ^longint;
  378.   shift   : word;
  379.   addmask : longint;
  380.   scan    : word;
  381.  
  382. begin
  383.   plotegavgacursor(2);
  384.  
  385.  
  386.   asm        { assembly time      }
  387.     pushf            { disable interrupts    }
  388.     cli
  389.     mov   dx, 3c4h
  390.     mov   ax, 0704h
  391.     out   dx, ax
  392.  
  393.     mov   dx, 03ceh  { graf controller port    }
  394.     mov   ax, 0204h  { map 2        }
  395.     out   dx, ax
  396.     mov   ax, 0005h  { disable odd-even adressing  }
  397.     out   dx, ax
  398.     mov   ax, 0406h  { map starts at A000:0000  }
  399.     out   dx, ax
  400.     popf
  401.   end;
  402.  
  403.   off:= 0;      { copy the char definitions  }
  404.   i:= 0;
  405.   while i< 3 do begin
  406.     s1:= LO(savechars[i][0])*32+((HI(savechars[i][0]) SHR 3) AND 1)*SecondaryFontOfs;
  407.     s2:= LO(savechars[i][1])*32+((HI(savechars[i][1]) SHR 3) AND 1)*SecondaryFontOfs;
  408.     s3:= LO(savechars[i][2])*32+((HI(savechars[i][2]) SHR 3) AND 1)*SecondaryFontOfs;
  409.     for j:= 0 to points-1 do begin
  410.       inc(off);
  411.       chardefs[off]:= Mem[$a000:s3]; inc(off); inc(s3);
  412.       chardefs[off]:= Mem[$a000:s2]; inc(off); inc(s2);
  413.       chardefs[off]:= Mem[$a000:s1]; inc(off); inc(s1);
  414.     end;
  415.     inc(i);
  416.   end;
  417.  
  418.   shift:= mousepx mod 8;    { Mask cursor      }
  419.   scan:= mousepy mod points;
  420.   asm
  421.     push   ds
  422.     pop    es
  423.     lea    di, chardefsL
  424.     add    di, scan
  425.     add    di, scan
  426.     add    di, scan
  427.     add    di, scan
  428.     lea    si, mousescreenmask
  429.     lea    bx, mousecursormask
  430.     mov    cx, cur_height
  431.     cld
  432.  
  433. @@l1:
  434.     push   cx
  435.  
  436.     lodsw
  437.     xchg   ax, dx        { ax= lo, dx= hi }
  438.     lodsw
  439.     xchg   ax, dx
  440.  
  441.     mov    cx, shift;
  442.     jcxz   @@noshr1
  443.  
  444. @@l2:
  445.     stc
  446.     rcr    dx, 1
  447.     rcr    ax, 1
  448.     loop   @@l2
  449.  
  450. @@noshr1:
  451.     and    word ptr [di], ax
  452.     and    word ptr [di].2, dx
  453.  
  454.     xchg   bx, si
  455.     lodsw
  456.     xchg   ax, dx
  457.     lodsw
  458.     xchg   ax, dx
  459.  
  460.     mov    cx, shift
  461.     jcxz   @@noshr2
  462.  
  463. @@l3:
  464.     stc
  465.     clc
  466.     rcr    dx, 1
  467.     rcr    ax, 1
  468.     loop   @@l3
  469.  
  470. @@noshr2:
  471.     or     word ptr [di], ax
  472.     or     word ptr [di].2, dx
  473.  
  474.     xchg   bx, si
  475.     add    di, 4
  476.  
  477.     pop    cx
  478.     loop   @@l1
  479.   end;
  480.  
  481.     
  482.  
  483.   asm        { copy the modified char set  }
  484.     mov  dx, 03c4h
  485.     mov  ax, 0402h
  486.     out  dx, ax
  487.   end;
  488.  
  489.   off:= 0;
  490.   i:= 0;
  491.   while i< 3 do begin
  492.     s1:= DEFCHAR[3*i  ]*32;
  493.     s2:= DEFCHAR[3*i+1]*32;
  494.     s3:= DEFCHAR[3*i+2]*32;
  495.  
  496.     for j:= 0 to points-1 do begin
  497.       inc(off);
  498.       Mem[$a000:s3] := chardefs[off]; inc(off); inc(s3);
  499.       Mem[$a000:s2] := chardefs[off]; inc(off); inc(s2);
  500.       mem[$a000:s1] := chardefs[off]; inc(off); inc(s1);
  501.     end;
  502.     inc(i);
  503.   end;
  504.  
  505.  
  506.   asm        { put the sequencer = normal  }
  507.     pushf            { disable interrupts    }
  508.     cli
  509.     mov   dx, 03c4h
  510.     mov   ax, 0302h
  511.     out   dx, ax
  512.     mov   ax, 0304h
  513.     out   dx, ax
  514.  
  515.     mov   dx, 03ceh  { program the controller  }
  516.     mov   ax, 0004h
  517.     out   dx, ax
  518.     mov   ax, 1005h
  519.     out   dx, ax
  520.     sub   ax, ax
  521.     mov   es, ax
  522.     mov   ax, 0e06h
  523.     mov   bl, 7
  524.     cmp   es:[49h], bl
  525.     jne   @@notmono
  526.     mov   ax, 0806h
  527. @@notmono:
  528.     out   dx, ax
  529.     popf
  530.   end;
  531.  
  532.   plotegavgacursor(1);
  533.  
  534. end;
  535.  
  536.  
  537.  
  538. {**********************************************************************
  539.   INTERNA: Rutina de atención al ratón;
  540. **********************************************************************}
  541. procedure old1c;  begin inline(0/0/0/0) end;
  542. procedure old33;  begin inline(0/0/0/0) end;
  543. procedure oldhandler;  begin inline(0/0/0/0) end;
  544.  
  545. procedure dummyhandler; far;
  546. begin
  547. end;
  548.  
  549. procedure mousehandler; far;
  550. const
  551.   evm  : word = 0;
  552.   evx  : word = 0;
  553.   evy  : word = 0;
  554.   conditionmask  : word = 0;
  555.   buttonstate    : word = 0;
  556. begin
  557.   asm
  558.     push  ds
  559.  
  560.     push  ax
  561.     xor   ax,ax
  562.     mov   ds,ax
  563.     inc   [word ptr ds:2]
  564.     mov   ax, SEG @DATA
  565.     mov   ds, ax
  566.     pop   ax
  567.  
  568.     mov   conditionmask, ax
  569.     mov   buttonstate, bx
  570.   end;
  571.  
  572.   if (mousefreeze= 0) then begin
  573.     asm
  574.       mov   mousex, cx
  575.       mov   mousey, dx
  576.       mov   mousepx, cx
  577.       mov   mousepy, dx
  578.     end;
  579.  
  580.     inhandler:= true;
  581.  
  582.     if (prettymousevisible) then begin
  583.       mousex:= mousex div 8;
  584.       mousey:= mousey div points;
  585.  
  586.       if (conditionmask and MOUSEMOVE<> 0) then begin
  587.         if (saved) then begin
  588.           plotegavgacursor(0);
  589.           saved:= false;
  590.         end;
  591.  
  592.  
  593.         if (mousehidden= 0) then begin
  594.           drawegavgacursor;
  595.           saved:= true;
  596.         end;
  597.       end;
  598.     end else begin
  599.       mousex:= mousex div 8;
  600.       mousey:= mousey div 8;
  601.     end;
  602.  
  603.  
  604.     { Se intenta no enviar eventos repetido a Turbo Visión      }
  605.     { Como el cursor esta en alta resolución hay ocho eventos   }
  606.     { horizontales y "b_points" verticales por cada evento TV   }
  607.     if not((mousex= evx) and (mousey= evy) and (conditionmask and MOUSEMOVE<> 0)) then begin
  608.       evx:= mousex;
  609.       evy:= mousey;
  610.  
  611.       asm
  612.         mov   ax, conditionmask
  613.         mov   bx, buttonstate
  614.         mov   cx, mousex
  615.         shl   cx, 1
  616.         shl   cx, 1
  617.         shl   cx, 1
  618.         mov   dx, mousey
  619.         shl   dx, 1
  620.         shl   dx, 1
  621.         shl   dx, 1
  622.         call  dword ptr cs:[oldhandler]
  623.       end;
  624.     end;
  625.  
  626.   end;
  627.  
  628.   inhandler:= false;
  629.   
  630.   asm
  631.     pop   ds
  632.   end;
  633. end;
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640. {**********************************************************************
  641.   INTERNA: Reset mouse
  642.  
  643.              Full== true  --> se desconecta el gestor de eventos
  644.                               (se utiliza cuando int 33h:ax=0)
  645.  
  646.              Full== false --> no se desconecta el gestor de eventos
  647.                               (se utiliza cunado se cambia de modo
  648.                                de video)
  649.  
  650. **********************************************************************}
  651. procedure MOUReset(full: boolean);
  652. var
  653.   v         : byte;
  654.   savevmode : byte;
  655.   biosmode  : byte absolute $40:$49;
  656.  
  657. begin
  658.   inc(mousefreeze);        { Semaforo                   }
  659.  
  660.   asm
  661.     mov   ax, 0f00h
  662.     int   10h
  663.     mov   v, al
  664.   end;
  665.  
  666.   if (v= 7) then
  667.     vseg:= $0b000
  668.   else begin
  669.     vseg:= $0b800;
  670.     v:= 3;
  671.   end;
  672.  
  673.   vofs  := {0 } 90*63*2;
  674.   mrows := {25} 63;
  675.   mcols := {80} 90;
  676.   points:= {16} 8;
  677.  
  678.   if (prettymousevisible) then begin
  679.     savevmode:= biosmode;
  680.     biosmode := 6;
  681.     asm                         { Engañamos al driver de raton  }
  682.       sub   ax, ax
  683.       pushf
  684.       call  dword ptr cs:[old33]
  685.     end;
  686.     biosmode:= savevmode;
  687.  
  688.     maxx:= mcols*8-1;
  689.     maxy:= mrows*points-1;
  690.   end else begin
  691.     asm
  692.       sub   ax, ax
  693.       pushf
  694.       call  dword ptr cs:[old33]
  695.     end;
  696.  
  697.     maxx:= (mcols-1)*8;
  698.     maxy:= (mrows-1)*8;
  699.   end;  
  700.       
  701.   asm                           { Ajustamos el rango del raton  }
  702.     mov   dx, maxx
  703.     mov   ax, 7
  704.     sub   cx, cx
  705.     pushf
  706.     call  dword ptr cs:[old33]
  707.  
  708.     mov   dx, maxy
  709.     mov   ax, 8
  710.     sub   cx, cx
  711.     pushf
  712.     call  dword ptr cs:[old33]
  713.  
  714.     mov   ax, cs                { Establecemos el gestor de eventos     }
  715.     mov   es, ax
  716.     mov   dx, offset mousehandler
  717.     mov   cx, 0ffffh
  718.     mov   ax, 12
  719.     pushf
  720.     call  dword ptr cs:[old33]
  721.   end;
  722.  
  723.   mousex:= 0;
  724.   mousey:= 0;
  725.   mousepx:= 0;
  726.   mousepy:= 0;
  727.  
  728.   asm                           { Colocamos el raton en el origen       }
  729.     mov   cx, mousex
  730.     mov   dx, mousey
  731.     mov   ax, 4
  732.     pushf
  733.     call  dword ptr cs:[old33]
  734.   end;
  735.  
  736.  
  737.   if (full) then asm
  738.     mov   ax, offset dummyhandler
  739.     mov   word ptr cs:oldhandler, ax
  740.     mov   ax, cs
  741.     mov   word ptr cs:oldhandler+2, ax
  742.   end;
  743.  
  744.   if (prettymousevisible) then begin
  745.     if (saved) then drawegavgacursor;
  746.   
  747.     mousehidden:= 1;
  748.     saved      := false;
  749.   end;
  750.  
  751.   dec(mousefreeze);
  752. end;
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761. {**********************************************************************
  762.   INTERNA: Hide mouse
  763.  
  764.              Esconde el raton
  765.  
  766. **********************************************************************}
  767. procedure MOUHide;
  768. begin
  769.   inc(mousefreeze);     { Semaforo      }
  770.  
  771.   if(prettymousevisible) then begin
  772.     inc(mousehidden);
  773.     if(saved) then
  774.       plotegavgacursor(0);
  775.     saved:= false;
  776.  
  777.   end else asm
  778.     mov   ax, 2
  779.     pushf
  780.     call  dword ptr cs:[old33]
  781.   end;
  782.  
  783.   dec(mousefreeze);  
  784. end;
  785.  
  786.  
  787.  
  788.  
  789. {**********************************************************************
  790.   INTERNA: Show mouse
  791.  
  792.              Muestra el raton
  793.  
  794. **********************************************************************}
  795. procedure MOUShow;
  796. begin
  797.   inc(mousefreeze);     { Semaforo      }
  798.  
  799.   if (prettymousevisible) then begin
  800.     if(mousehidden> 0) then
  801.       dec(mousehidden)
  802.     else begin
  803.       dec(mousefreeze);
  804.       exit;
  805.     end;
  806.  
  807.     if(mousehidden> 0) then begin
  808.       dec(mousefreeze);
  809.       exit;
  810.     end;
  811.  
  812.     drawegavgacursor;
  813.     saved:= true;
  814.  
  815.   end else asm
  816.     mov   ax, 0001
  817.     pushf
  818.     call  dword ptr cs:[old33]
  819.   end;
  820.  
  821.   dec(mousefreeze);
  822. end;
  823.  
  824.  
  825.  
  826.  
  827.  
  828. {**********************************************************************
  829.   INTERNA: Int1c
  830.  
  831.              Gestor de la interrupcion 1c
  832.  
  833. **********************************************************************}
  834. procedure int1c; interrupt;
  835. label
  836.   fin;
  837. CONST
  838.   Semaph : BOOLEAN = FALSE;
  839. var
  840.   off      : word;
  841.   width,
  842.   height,
  843.   disp     : word;
  844.   x,
  845.   y        : word;
  846.   p1       : pointer;
  847.   repaint  : word;
  848.  
  849. begin
  850.   asm
  851.     STI
  852.     pushf
  853.     call     dword ptr cs:[old1c]
  854.   end;  
  855.  
  856.   IF Semaph THEN EXIT;
  857.   Semaph := TRUE;
  858.  
  859.   if not prettymousevisible then exit;
  860.   
  861.   if(mousefreeze<> 0) then goto fin;
  862.   if(inhandler) then goto fin;
  863.  
  864.   plotegavgacursor(0);
  865.   drawegavgacursor;
  866.  
  867. fin:
  868.   Semaph := FALSE;
  869. end;
  870.  
  871.  
  872.  
  873.  
  874.  
  875. {**********************************************************************
  876.   INTERNA: Int33
  877.  
  878.              Gestor de la interrupcion 33h
  879.  
  880. **********************************************************************}
  881. procedure int33; far; assembler;
  882. asm
  883.   push  ds
  884.   push  ax
  885.   mov   ax, seg @data
  886.   mov   ds, ax
  887.   pop   ax
  888.  
  889. {
  890.         cmp     MouseEvents,0
  891.         jz      @@bypass
  892. }        
  893.  
  894.   or    ax, ax          { Discriminamos los servicios que vamos a usar  }
  895.   je    @@doit
  896.   cmp   ax, 1
  897.   je    @@doit
  898.   cmp   ax, 2
  899.   je    @@doit
  900.   cmp   ax, 3
  901.   je    @@doit
  902.   cmp   ax, 4
  903.   je    @@doit
  904.   cmp   ax, 7
  905.   je    @@doit
  906.   cmp   ax, 8
  907.   je    @@doit
  908.   cmp   ax, 0ch
  909.   je    @@doit
  910.  
  911. @@bypass:
  912.   pop   ds
  913.   jmp   dword ptr cs:[old33]
  914.  
  915.  
  916. @@doit:
  917.   push  es              { Salvar los registros                          }
  918.   push  ax
  919.   push  bx
  920.   push  cx
  921.   push  dx
  922.   push  si
  923.   push  di
  924.   push  bp
  925.  
  926. {
  927.   push  ax
  928.  
  929.   mov   ax, seg @data
  930.   mov   ds, ax
  931.  
  932.   pop   ax
  933. }
  934.  
  935.   mov   bp, sp
  936.  
  937.   or    ax, ax
  938.   je    @@reset
  939.   cmp   ax, 1
  940.   je    @@show
  941.   cmp   ax, 2
  942.   je    @@hide
  943.   cmp   ax, 3
  944.   je    @@getinfo
  945.   cmp   ax, 4
  946.   je    @@setpos
  947.   cmp   ax, 7
  948.   je    @@rangeX
  949.   cmp   ax, 8
  950.   je    @@rangeY
  951.   jmp   @@defuser
  952.  
  953. @@show:
  954.   call  MOUShow;
  955.   jmp   @@out
  956.  
  957. @@hide:
  958.   call  MOUHide;
  959.   jmp   @@out
  960.  
  961. @@reset:
  962.   xor   ax, ax
  963.   pushf
  964.   call  dword ptr cs:[old33]
  965.   mov   ss:[bp].12, ax
  966.   mov   ss:[bp].10, bx
  967.  
  968.   mov   ax, 1
  969.   push  ax
  970.   call  MOUReset
  971.  
  972.   jmp   @@out
  973.  
  974. @@getinfo:
  975.   pushf
  976.   call  dword ptr cs:[old33]
  977.   mov   ss:[bp].10, bx
  978.   and   cx, 0fff8h
  979.   mov   ss:[bp].8,  cx
  980.   mov   ax, dx
  981.   shl   ax, 1
  982.   shl   ax, 1
  983.   shl   ax, 1
  984.   mov   bx, points
  985.   xor   dx, dx
  986.   div   bx
  987.   mov   ss:[bp].6, ax
  988.   jmp   @@out
  989.  
  990. @@setpos:
  991.   push  ax
  992.   mov   ax, dx
  993.   mov   bx, points
  994.   mul   bx
  995.   shr   ax, 1
  996.   shr   ax, 1
  997.   shr   ax, 1
  998.   mov   dx, ax
  999.   pop   ax
  1000.  
  1001.   pushf
  1002.   call  dword ptr cs:[old33]
  1003.   jmp   @@out
  1004.  
  1005. @@rangeX:
  1006. {
  1007.   mov   dx, maxx
  1008.   pushf
  1009.   call  dword ptr cs:[old33]
  1010. }  
  1011.   sub   ax, ax
  1012.   push  ax
  1013.   call  MOUReset
  1014.   
  1015.   jmp   @@out
  1016.  
  1017. @@rangeY:
  1018. {
  1019.   mov   dx, maxy
  1020.   pushf
  1021.   call  dword ptr cs:[old33]
  1022. }
  1023.   sub   ax, ax
  1024.   push  ax
  1025.   call  MOUReset
  1026.  
  1027.   jmp   @@out
  1028.  
  1029. @@defuser:
  1030.   push  es
  1031.   push  dx
  1032.   pop   word ptr cs:oldhandler
  1033.   pop   word ptr cs:oldhandler+2
  1034.  
  1035.   push  cs
  1036.   pop   es
  1037.   mov   dx, offset mousehandler
  1038.   pushf
  1039.   call  dword ptr cs:[old33]
  1040.  
  1041.  
  1042.  
  1043.  
  1044. @@out:
  1045.   pop   bp
  1046.   pop   di
  1047.   pop   si
  1048.   pop   dx
  1049.   pop   cx
  1050.   pop   bx
  1051.   pop   ax
  1052.   pop   es
  1053.   pop   ds
  1054.   retf  2
  1055. end;  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. {**********************************************************************
  1061.   PUBLICA: Conexión del ratón
  1062.  
  1063.              Inicializacion y terminacion del raton
  1064.  
  1065. **********************************************************************}
  1066. var
  1067.   SaveExit: POINTER;
  1068.  
  1069. procedure ExitMOU; far;
  1070. begin
  1071.   DoneMouse;
  1072.   ExitProc := SaveExit;
  1073. end;
  1074.  
  1075.  
  1076. procedure InitMouse;
  1077. begin
  1078.   if (prettymouseavail) then exit;
  1079.  
  1080.   prettymousevisible:= false;
  1081.  
  1082. {
  1083.   if not MouseAvail then Exit;
  1084. }
  1085.  
  1086.   asm
  1087.     sub   ax,ax;          { Mouse driver function 0 -- reset and detect }
  1088.     int   33h
  1089.     mov   prettymouseavail,AL;
  1090.   end;
  1091.  
  1092.   if not prettymouseavail then Exit;
  1093.  
  1094.   asm
  1095.     mov   ax, 3533h                     { driver de raton               }
  1096.     int   21h
  1097.     mov   word ptr cs:old33, bx
  1098.     mov   word ptr cs:old33+2, es
  1099.  
  1100.     mov   ax, 351ch            { reloj             }
  1101.     int   21h
  1102.     mov   word ptr cs:old1c, bx
  1103.     mov   word ptr cs:old1c+2, es
  1104.  
  1105.     push  ds
  1106.  
  1107.     mov   ax, 2533h
  1108.     mov   dx, offset int33
  1109.     push  cs
  1110.     pop   ds
  1111.     int   21h
  1112.     
  1113.     mov   ax, 251ch
  1114.     mov   dx, offset int1c
  1115.     int   21h
  1116.  
  1117.     pop   ds
  1118.   end;
  1119.  
  1120.   MOUReset(TRUE);
  1121.  
  1122.   SelectMouseCursor(mouPointer);
  1123.   
  1124.   SaveExit := ExitProc;
  1125.   ExitProc := @ExitMOU;
  1126. end;
  1127.  
  1128.  
  1129. procedure DoneMouse;
  1130. begin
  1131.   if (prettymouseavail) then asm
  1132.     push  ds
  1133.     mov   ax, word ptr cs:[old33].2
  1134.     mov   ds, ax
  1135.     mov   dx, word ptr cs:[old33]
  1136.     mov   ax, 2533h
  1137.     int   21h
  1138.     pop   ds
  1139.     
  1140.     push  ds
  1141.     mov   ax, word ptr cs:[old1c].2
  1142.     mov   ds, ax
  1143.     mov   dx, word ptr cs:[old1c]
  1144.     mov   ax, 251ch
  1145.     int   21h
  1146.     pop   ds
  1147.   end;
  1148.  
  1149.   MOUHide;
  1150.  
  1151.   prettymouseavail:= false;
  1152. end;
  1153.  
  1154.  
  1155. procedure SetMouse(On: boolean);
  1156. begin
  1157.   if not MouseAvail then Exit;
  1158.  
  1159.   InitMouse;               { Garantiza que el raton grafico esta inicializado }
  1160.  
  1161.   if prettymousevisible = On then Exit; { Optimiza el funcionamiento }
  1162.  
  1163.   MOUHide;                 { Esconde el ratón }
  1164.   prettymousevisible:= On; { Conmuta al tipo de ratón requerido }
  1165.   MOUReset(false);         { Reajusta los parámetros del ratón }
  1166.   MOUShow;                 { Visualiza el ratón }
  1167. end;
  1168.  
  1169.  
  1170.  
  1171. function MouseAvail:boolean;
  1172. begin
  1173.   MouseAvail := TRUE;
  1174.   if prettymouseavail then Exit;
  1175.  
  1176.   MouseAvail := FALSE;
  1177. (*
  1178.   if DeskViewPresent or                  { DeskView no permite ratón grafico }
  1179.      (WindowsPresent=386) then Exit;     { Windows /3 no permite en ventana  }
  1180.   MouseAvail := TRUE;
  1181. *)
  1182. end;
  1183.  
  1184.  
  1185.  
  1186. procedure RepaintMouse;            { Repinta el raton, puede ser llamado desde el idle }
  1187. begin
  1188. end;  
  1189.  
  1190.  
  1191. procedure SelectMouseCursor(mouCur: word);
  1192. begin
  1193.   if(prettymouseavail) then begin
  1194.     inc(mousefreeze);
  1195.     MOUHide;
  1196.     case mouCur of
  1197.       mouPointer: begin
  1198.         move(cur_Pointer_fore, mousecursormask, cur_height*sizeof(longint));
  1199.         move(cur_Pointer_back, mousescreenmask, cur_height*sizeof(longint));
  1200.       end;
  1201.       mouWaitClock: begin
  1202. {
  1203.         move(cur_WaitClock_fore, mousecursormask, cur_height*sizeof(longint));
  1204.         move(cur_WaitClock_back, mousescreenmask, cur_height*sizeof(longint));
  1205. }
  1206.       end else begin
  1207.         move(cur_Pointer_fore, mousecursormask, cur_height*sizeof(longint));
  1208.         move(cur_Pointer_back, mousescreenmask, cur_height*sizeof(longint));
  1209.       end;
  1210.     end;
  1211.     MOUShow;
  1212.     dec(mousefreeze);
  1213.   end;
  1214. end;
  1215.  
  1216.  
  1217. PROCEDURE ShowMouse; ASSEMBLER;
  1218.   ASM
  1219.                 MOV     AH,1
  1220.                 INT     $33
  1221.   END;
  1222.  
  1223.  
  1224.  
  1225. PROCEDURE HideMouse; ASSEMBLER;
  1226.   ASM
  1227.                 MOV     AH,2
  1228.                 INT     $33
  1229.   END;
  1230.  
  1231.  
  1232.  
  1233. end.
  1234.